package authenum

import (
	"yunj/pkg/yunj/core/enum"
)

// 定义常量
const (
	REQUEST_METHOD_ANY    string = ""
	REQUEST_METHOD_GET    string = "GET"
	REQUEST_METHOD_POST   string = "POST"
	REQUEST_METHOD_PUT    string = "PUT"
	REQUEST_METHOD_DELETE string = "DELETE"
)

// 实现EnumInerface接口
type RequestMethod struct {
	enum.Enum[string]
}

func (e *RequestMethod) AllConstAttrs() map[string]map[string]any {
	return map[string]map[string]any{
		REQUEST_METHOD_ANY: {
			"desc": "ANY",
			"sort": 1,
		},
		REQUEST_METHOD_GET: {
			"desc": "GET",
			"sort": 2,
		},
		REQUEST_METHOD_POST: {
			"desc": "POST",
			"sort": 3,
		},
		REQUEST_METHOD_PUT: {
			"desc": "PUT",
			"sort": 4,
		},
		REQUEST_METHOD_DELETE: {
			"desc": "DELETE",
			"sort": 5,
		},
	}
}

// instanceCache 存储已经创建的实例
var requestMethodInstanceCache = make(map[string]*RequestMethod)

// 根据value获取枚举
func RequestMethodByValue(value string) *RequestMethod {
	if instance, exists := requestMethodInstanceCache[value]; exists {
		return instance
	}
	e := &RequestMethod{}
	enum.SetEnumInstance(&e.Enum, e, value)
	requestMethodInstanceCache[value] = e
	return e
}

var RequestMethodEnum *RequestMethod = func() *RequestMethod {
	e := &RequestMethod{}
	enum.SetEnumInstance(&e.Enum, e)
	return e
}()
